import axios from 'axios'
import md5 from 'js-md5'
import qs from 'qs'
import { URLHEAD } from '@/config/global'

export const fetchDataLocal = (url, params) => {
    let fetchedData = null;
    return new Promise(resolve => {
        axios.get(URLHEAD.attach + url, {
            params: params
        }).then(res => {
            fetchedData = res.data;
            resolve(res.data);
            console.dir(fetchedData);
        }).catch(e => {
            console.error(`${URLHEAD.attach + url}请求数据出错，请求参数如下：`);
            console.dir(params);
        })
    });
}
let urlPrefix = "http://112.74.172.211:8001/api/v1/"
export const fetchDataGet = (url, params) => {
    let fetchedData = null;
    return new Promise(resolve => {
        axios.get(`${urlPrefix}${url}`, {
            params: params
        }).then(res => {
            fetchedData = res.data;
            resolve(res.data);
            console.dir(fetchedData);
        }).catch(e => {
            console.error(`${`http://112.74.172.211:8001/api/v1/` + url}请求数据出错，请求参数如下：`);
            console.dir(params);
        })
    });
}
export const fetchDataPost = (url, params) => {
    let fetchedData = null;
    return new Promise(resolve => {
        axios.post(`${urlPrefix}${url}`,
            params).then(res => {
                fetchedData = res.data;
                resolve(res.data);
                console.dir(fetchedData);
            }).catch(e => {
                console.error(e, `${urlPrefix}${url}`, params);
            })
    })
}
